<template>
	<view class="uni-login-box" :style="!show ? 'z-index:-1;opacity:0' : 'z-index:9;opacity:1'" @tap="refuse">
		<view class="sharebanner" >
			<view class="sharebanner_bg" @tap.stop="">
				<image :src="sharePic" mode="widthFix"></image>
			</view>
			<view class="save_pic" @tap.stop="down">
				<image :src="Url + 'add_images/download.png'"></image>
				保存图片
			</view>
		</view>
	</view>
</template>

<script>
	import {share} from '@/common/productdetail.js';
	import {
		sellerService,
	} from '@/common/mine.js';
	export default {
		props:['productId','tag'],
		data() {
			return {
				Url: this.Imgurl,
				show: false,
				sharePic:'',
			}
		},
		created() {
			this.getData()
		},
		methods: {
			refuse() {
				this.show = false;
			},
			getData() {
				let version = uni.getSystemInfoSync().version ? 1:2;
				let params = {
					id:this.productId,
					version:version,
					active_tag:this.tag
				}
				// uni.showLoading({
				// 	title:'图片生成中'
				// });
				share(params).then(res=>{
					console.log(res)
					if(res.code == 1){
						this.sharePic = res.msg
					}else{
						this.toast(res.msg)
					}
					// uni.hideLoading();
				}).catch()
			},
			// 保存图片
			down() {
				var version = uni.getSystemInfoSync().version;
				if (version) {
					this.resultVersion();
				} else {
					uni.showModal({
						title: '提示',
						content: '长按图片保存',
						showCancel: false,
						cancelText: '',
						confirmText: '确定',
						success: res => {},
						fail: () => {},
						complete: () => {}
					});
				}
			},
			//小程序
			resultVersion(){
				uni.showLoading({
					title:'正在保存'
				})
				uni.downloadFile({
						url: this.sharePic,
						success: (res) =>{
							if (res.statusCode === 200){
								uni.hideLoading();
								uni.saveImageToPhotosAlbum({
									filePath: res.tempFilePath,
									success: function() {
										uni.hideLoading();
										uni.showToast({
											title: "保存成功",
											icon: "none"
										});
									},
									fail: function() {
										uni.hideLoading();
										uni.showToast({
											title: "保存失败，请稍后重试",
											icon: "none"
										});
									}
								});
							}
						},
						fail:(res)=>{
							console.log(res)
						}
					})
			},
		}

	}
</script>

<style lang="less" scoped>
	.uni-login-box {
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
		background: rgba(0, 0, 0, 0.5);
		transition: all 0.2s linear;
	}
	.sharebanner{
		position: fixed;
		top: 50%;
		left: 50%;
		transform: translate(-50%,-50%);
	}
	.sharebanner_bg {
		width: 560upx;
		// height: 950upx;
		overflow: hidden;
		position: relative;
	
		image {
			width: 100%;
			height: 100%;
			border-radius: 15upx;
			
		}
	}
	
	.save_pic {
		width: 250upx;
		height: 80upx;
		box-sizing: border-box;
		font-size: 32upx;
		color: #FFFFFF;
		text-align: center;
		line-height: 80upx;
		border-radius: 40upx;
		margin: auto;
		margin-top: 30upx;
		background: #0390FD;
		display: flex;
		justify-content: center;
		align-items: center;
		image{
			margin-right: 10upx;
			width: 38upx;
			height: 34upx;
		}
	}
</style>
